//
//  PersonalCenterViewController.m
//  suRead
//
//  Created by 龚浩植 on 15/11/11.
//  Copyright © 2015年 bao. All rights reserved.
//

#import "PersonalCenterViewController.h"
#import "LoginViewController.h"
#import "AccountManager.h"
#import "PublishFeedBackViewController.h"
#import "MyCommentViewController.h"
#import "UIViewController+HUD.h"

@interface PersonalCenterViewController ()

@property (strong, nonatomic) IBOutlet UILabel *nameLable;
@property (strong, nonatomic) IBOutlet UIButton *loginButton;

@end

@implementation PersonalCenterViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.tableView.sectionHeaderHeight = 0;
    self.tableView.contentInset = UIEdgeInsetsMake(-2.0f, 0.0f, 0.0f, 0.0);
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:YES];
    if ([AccountManager sharedAccountManager].f_isLogined) {
        [self.nameLable setText:[AccountManager sharedAccountManager].f_userName];
        self.loginButton.hidden = YES;
    }else {
        [self.nameLable setText:@""];
        self.loginButton.hidden = NO;
    }
}

#pragma mark - Table view data source
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        return [UIScreen mainScreen].bounds.size.width * (504.0f / 720.0f);
    }
    return 44.0f;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 0) {
        return  1.0f;
    }
    return 10.0f;
}

#pragma mark - Table view data source
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    switch (indexPath.section)
    {
        case 1:
        {
            if (indexPath.row == 1) {
                if ([AccountManager sharedAccountManager].f_isLogined) {
                    MyCommentViewController *myCommentViewController = [[MyCommentViewController alloc] init];
                    [self.navigationController pushViewController:myCommentViewController animated:YES];
                }else{
                    [self showHUDText:@"请先登录"];
                }
            }

            if (indexPath.row == 2) {
                UIStoryboard *PersonalStoryboard = [UIStoryboard storyboardWithName:@"PersonalCenter" bundle:[NSBundle mainBundle]];
                PublishFeedBackViewController *controller = [PersonalStoryboard instantiateViewControllerWithIdentifier:@"PublishFeedBackViewController"];
                [self.navigationController pushViewController:controller animated:YES];
            }
        }
            break;
            
        case 2:
        {
            if (indexPath.row == 0)
            {                
                break;
            }
        }
        default:
            break;
    }
     [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
}

#pragma mark - click

- (IBAction)goLogin:(id)sender
{
    UIStoryboard *personalCenter = [UIStoryboard storyboardWithName:@"PersonalCenter" bundle:[NSBundle mainBundle]];
    LoginViewController *controller = [personalCenter instantiateViewControllerWithIdentifier:@"LoginViewController"];
    [self.navigationController pushViewController:controller animated:YES];
}

- (IBAction)goBack:(id)sender
{
    [self.navigationController popViewControllerAnimated:YES];
    [self dismissViewControllerAnimated:YES completion:nil];
}

@end
